home *** CD-ROM | disk | FTP | other *** search
/ Chip 2006 June (Extra) / CHIP 2006-06.3.iso / program / opensource / clamav-devel.exe / contrib / Windows / progress.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2006-05-16  |  2.8 KB  |  119 lines

  1. // progress.cpp : implementation file
  2. //
  3.  
  4. /*
  5.  *  Copyright (C) 2004 Nigel Horne <njh@bandsman.co.uk>
  6.  *
  7.  *  This program is free software; you can redistribute it and/or modify
  8.  *  it under the terms of the GNU General Public License as published by
  9.  *  the Free Software Foundation; either version 2 of the License, or
  10.  *  (at your option) any later version.
  11.  *
  12.  *  This program is distributed in the hope that it will be useful,
  13.  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  14.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15.  *  GNU General Public License for more details.
  16.  *
  17.  *  You should have received a copy of the GNU General Public License
  18.  *  along with this program; if not, write to the Free Software
  19.  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
  20.  *  MA 02110-1301, USA.
  21.  */
  22. #include "stdafx.h"
  23. #include "clamav.h"
  24.  
  25. #include "progress.h"
  26.  
  27. #ifdef _DEBUG
  28. #undef THIS_FILE
  29. static char BASED_CODE THIS_FILE[] = __FILE__;
  30. #endif
  31.  
  32. /////////////////////////////////////////////////////////////////////////////
  33. // CProgress dialog
  34.  
  35.  
  36. CProgress::CProgress(CWnd* pParent)
  37.     : CDialog(CProgress::IDD, pParent)
  38. {
  39.     //{{AFX_DATA_INIT(CProgress)
  40.     m_filename = _T("bar");
  41.     m_percent = _T("");
  42.     //}}AFX_DATA_INIT
  43.     stopPressed = FALSE;
  44. }
  45.  
  46.  
  47. void CProgress::DoDataExchange(CDataExchange* pDX)
  48. {
  49.     CDialog::DoDataExchange(pDX);
  50.     //{{AFX_DATA_MAP(CProgress)
  51.     DDX_Text(pDX, IDC_FileName, m_filename);
  52.     DDX_Text(pDX, IDC_Percent, m_percent);
  53.     //}}AFX_DATA_MAP
  54. }
  55.  
  56. void
  57. CProgress::SetFilename(const CString& filename)
  58. {
  59.     if(stopPressed)
  60.         return;
  61.  
  62.     m_filename = _T(filename);
  63.  
  64.     CStatic *text = (CStatic *)GetDlgItem(IDC_FileName);
  65.     if(text) {
  66.         text->SetWindowText(filename);
  67.         // text->UpdateWindow();
  68.         percent = -1;    // force a display when it changes
  69.     } else
  70.         AfxMessageBox("Can't find IDC_FileName");
  71. }
  72.  
  73. void
  74. CProgress::SetPercent(int p)
  75. {
  76.     if((p < 0) || (p > 100))
  77.         return;
  78.  
  79.     if(p == percent)
  80.         return;
  81.  
  82.     char buf[5];
  83.     sprintf(buf, "%d%%", p);
  84.  
  85.     CStatic *text = (CStatic *)GetDlgItem(IDC_Percent);
  86.     if(text) {
  87.         text->SetWindowText(buf);
  88.         // text->UpdateWindow();
  89.         percent = p;
  90.     } else
  91.         AfxMessageBox("Can't find IDC_Percent");
  92. }    
  93.  
  94. const BOOL
  95. CProgress::IsStopPressed(void)
  96. {
  97.     return stopPressed;
  98. }
  99.  
  100. BEGIN_MESSAGE_MAP(CProgress, CDialog)
  101.     //{{AFX_MSG_MAP(CProgress)
  102.     ON_BN_CLICKED(IDSTOP, OnStop)
  103.     //}}AFX_MSG_MAP
  104. END_MESSAGE_MAP()
  105.  
  106.  
  107. /////////////////////////////////////////////////////////////////////////////
  108. // CProgress message handlers
  109.  
  110. void CProgress::OnStop() 
  111. {
  112.     // TODO: Add your control notification handler code here
  113.     stopPressed = TRUE;
  114.  
  115.     CButton *stopButton = (CButton *)GetDlgItem(IDSTOP);
  116.     if(stopButton)
  117.         stopButton->EnableWindow(FALSE);
  118. }
  119.